<template>
  <div
    class="designer-property-panel property-panel"
    :style="{ width: propertyPanelWidth + 'px' }"
    v-if="selectedNode || selectedEdge"
  >
    <!-- 拖拽条 -->
    <div class="panel-resizer" @mousedown="startResize" />
    <el-card class="panel-card">
      <template #header>
        <span></span>
        <el-button class="panel-close-btn" type="text" size="default" @click="closePanel" title="关闭">
          <span class="close-x">×</span>
        </el-button>
      </template>
      <div class="panel-content">
        <!-- 节点属性面板 -->
        <template v-if="selectedNode">
          <NodePropertyPanel 
            :node="selectedNode" 
            :property-panel="propertyPanel"
            @property-change="onPropertyChange"
            @delete="handleDelete"
            @open-selector="onOpenSelector"
          />
        </template>
        
        <!-- 连线属性面板 -->
        <template v-else-if="selectedEdge">
          <EdgePropertyPanel 
            :edge="selectedEdge" 
            :property-panel="propertyPanel"
            @property-change="onEdgePropertyChange"
            @delete="handleDelete"
          />
        </template>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import NodePropertyPanel from './NodePropertyPanel.vue'
import EdgePropertyPanel from './EdgePropertyPanel.vue'

const props = defineProps({
  selectedNode: Object,
  selectedEdge: Object,
  propertyPanel: Object,
  propertyPanelWidth: Number
})

const emit = defineEmits(['propertyChange', 'edgePropertyChange', 'delete', 'close', 'resize', 'openSelector'])

/**
 * 处理节点属性变更
 */
function onPropertyChange() {
  emit('propertyChange')
}

/**
 * 处理连线属性变更
 */
function onEdgePropertyChange() {
  emit('edgePropertyChange')
}

/**
 * 处理删除操作
 */
function handleDelete() {
  emit('delete')
}

/**
 * 关闭面板
 */
function closePanel() {
  emit('close')
}

/**
 * 开始调整面板大小
 */
function startResize(e) {
  emit('resize', e)
}

/**
 * 处理打开选择器
 */
function onOpenSelector(data) {
  console.log('PropertyPanel - onOpenSelector called:', data)
  emit('openSelector', data)
}
</script>

<style scoped>
.designer-property-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 420px;
  height: 100%;
  background: #fafbfc;
  border-left: 1px solid #eee;
  padding: 0;
  overflow: hidden;
  z-index: 20;
  transition: width 0.15s;
  box-sizing: border-box;
  min-width: 320px;
  max-width: 800px;
  display: flex;
  flex-direction: column;
}

.panel-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel-card :deep(.el-card__body) {
  flex: 1;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-card :deep(.el-card__header) {
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
  background: #fafbfc;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 32px 20px 16px;
}

.panel-content::-webkit-scrollbar {
  width: 6px;
}

.panel-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.panel-resizer {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  z-index: 30;
  transition: background 0.2s;
}

.panel-resizer:hover {
  background: #e4e7ed44;
}

.panel-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  padding: 0;
  min-width: 32px;
  min-height: 32px;
  color: #909399;
  background: transparent;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}

.panel-close-btn:hover {
  background: #f56c6c22;
  color: #f56c6c;
}

.close-x {
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  display: inline-block;
  color: inherit;
}

/* 夜间模式适配 */
[data-theme='dark'] .designer-property-panel {
  background: #2a2a2a !important;
  border-left: 1px solid #444 !important;
}

[data-theme='dark'] .panel-card {
  background: #2a2a2a !important;
}

[data-theme='dark'] .panel-card :deep(.el-card__header) {
  background: #3a3a3a !important;
  border-bottom: 1px solid #555 !important;
  color: #fff !important;
}

[data-theme='dark'] .panel-card :deep(.el-card__body) {
  background: #2a2a2a !important;
}

[data-theme='dark'] .panel-content {
  background: #2a2a2a !important;
}

[data-theme='dark'] .panel-content::-webkit-scrollbar-track {
  background: #3a3a3a !important;
}

[data-theme='dark'] .panel-content::-webkit-scrollbar-thumb {
  background: #666 !important;
}

[data-theme='dark'] .panel-content::-webkit-scrollbar-thumb:hover {
  background: #888 !important;
}

[data-theme='dark'] .panel-resizer:hover {
  background: rgba(255,255,255,0.1) !important;
}

[data-theme='dark'] .panel-close-btn {
  color: #ccc !important;
}

[data-theme='dark'] .panel-close-btn:hover {
  background: rgba(245,108,108,0.2) !important;
  color: #f56c6c !important;
}
</style> 